package processes;

import to.MaterialTO;
import util.DateUtil;
import util.MaterialParser;
import util.ProductParser;

public class CuttingMachine extends Machine{
	public CuttingMachine(MachineManager machineManager, String machineId) {
		super(1500,1000, machineManager, machineId);
	}
	
	@Override
	public void beforeManufacture() {
		MaterialParser mp = MaterialParser.getInstance();
		
		MaterialTO cotton = mp.readMaterial("M1");
		int size = getWork().getSize();
		cotton.setQuantity(cotton.getQuantity()-size);
		mp.writeMaterial(cotton);
		mp.returnKey();
	}
	
	@Override
	public void afterManufacture() {
		currentProduct.setCuttingQuality(generateQuality());
		currentProduct.setCuttingDate(DateUtil.getInstance().getCurrentTimeString());
		currentProduct.setCuttingId(getMachineId());
		currentProduct.setCuttingTime((int)(DateUtil.getInstance().getCurrentTimeLong()-getStartTime()));
		ProductParser pp = ProductParser.getInstance();
		pp.writeProduct(machineManager.getNextDir(), currentProduct);
	}
}
